package com.mobiporter.adias.core;

import com.mobiporter.utils.StringUtils;

import net.sourceforge.wurfl.wurflapi.CapabilityMatrix;
import net.sourceforge.wurfl.wurflapi.OMWrapper;
import net.sourceforge.wurfl.wurflapi.UAManager;

public class Manager 
{
	public static boolean isSelectBoxEnabled(String userAgent)
	{
		CapabilityMatrix cm = OMWrapper.getObjectsManager().getCapabilityMatrix();
        UAManager uam =OMWrapper.getObjectsManager().getUAManager();
        String deviceId = uam.getDeviceIDFromUALoose(userAgent);
        String asRadios = cm.getCapabilityForDevice(deviceId, "xhtml_select_as_radiobutton");
        boolean decision = !(StringUtils.getBoolean(asRadios)) ;
        return decision;
	}
	
	public static boolean hasTableSupport(String userAgent)
	{
		CapabilityMatrix cm = OMWrapper.getObjectsManager().getCapabilityMatrix();
        UAManager uam =OMWrapper.getObjectsManager().getUAManager();
        String deviceId = uam.getDeviceIDFromUALoose(userAgent);
        String asRadios = cm.getCapabilityForDevice(deviceId, "table_support");
        boolean decision = (StringUtils.getBoolean(asRadios)) ;
        return decision;
	}
	
	public static String getScreenWidth(String userAgent)
	{
		CapabilityMatrix cm = OMWrapper.getObjectsManager().getCapabilityMatrix();
        UAManager uam =OMWrapper.getObjectsManager().getUAManager();
        String deviceId = uam.getDeviceIDFromUALoose(userAgent);
        String width = cm.getCapabilityForDevice(deviceId, "resolution_width");
        if (width==null)
        	return "172";
        return width;
	}
	
	public static String getMakePhoneCallString(String userAgent)
	{
		CapabilityMatrix cm = OMWrapper.getObjectsManager().getCapabilityMatrix();
        UAManager uam =OMWrapper.getObjectsManager().getUAManager();
        String deviceId = uam.getDeviceIDFromUALoose(userAgent);
        String telephoneString = cm.getCapabilityForDevice(deviceId, "xhtml_make_phone_call_string");
        if (telephoneString==null || telephoneString.trim().equals("") || telephoneString.trim().toLowerCase().equals("none"))
        {
        	return "wtai://wp/mc;";
        }
        return telephoneString;
	}
}
